﻿using System.Collections.Generic;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using XnReader.WinRT.Forms;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace XnReader.WinRT.Controlx
{
    public sealed partial class NavDx : UserControl
    {
        public NavDx()
        {
            InitializeComponent();
            var nav = new NavInfoDx();
            cvsLeft.Source = nav.GetLeftNavInfos();
            cvsRight.Source = nav.GetRightNavInfos();
        }

        public void SelectItem(int sortid)
        {
            if(cvsLeft!=null)
            {
                var list = (cvsLeft.Source) as IList<NavInfoDx>;
                if (list != null)
                {
                    foreach (NavInfoDx nav in list)
                    {
                        if(nav.Id.Equals(sortid))
                        {
                            gvLeftNavs.SelectedItem = nav;
                        }
                    }
                }
            }
        }

        private void GvLeftNavsItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem != null)
            {
                var nav = e.ClickedItem as NavInfoDx;
                if (nav != null)
                {
                    var rootFrame = Window.Current.Content as Frame;
                    if (rootFrame != null) rootFrame.Navigate(typeof(OnlineArticleList), nav.Id);
                }
            }
        }

        private void GvRightNavsItemClick(object sender, ItemClickEventArgs e)
        {
            if (e.ClickedItem != null)
            {
                var nav = e.ClickedItem as NavInfoDx;
                if (nav != null)
                {
                    var rootFrame = Window.Current.Content as Frame;
                    if (rootFrame != null)
                    {
                        rootFrame.Navigate(typeof(Bookcase));
                    }
                }
            }
        }
    }

    public class NavInfoDx
    {
        public int Id { get; set; }

        public string Title { get; set; }

        public string Tips { get; set; }

        public SolidColorBrush BackColor { get; set; }

        public string Image { get; set; }

        public IList<NavInfoDx> GetLeftNavInfos()
        {
            IList<NavInfoDx> list = new List<NavInfoDx>();
            var navInfo0 = new NavInfoDx
            {
                Id = 1001,
                Title = "最新",
                Tips = "最新更新",
                Image = "⛺",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 17, 174, 122))
            };
            list.Add(navInfo0);
            var navInfo2 = new NavInfoDx
            {
                Id = 1,
                Title = "玄幻",
                Tips = "玄幻奇幻",
                Image = "✡",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 138, 174, 16))
            };
            list.Add(navInfo2);
            var navInfo3 = new NavInfoDx
            {
                Id = 2,
                Title = "武侠",
                Tips = "武侠仙侠",
                Image = "☯",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 83, 252, 194))
            };
            list.Add(navInfo3);
            var navInfo4 = new NavInfoDx
            {
                Id = 3,
                Title = "言情",
                Tips = "都市言情",
                Image = "⚭",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 233, 171, 22))
            };
            list.Add(navInfo4);
            var navInfo5 = new NavInfoDx
            {
                Id = 4,
                Title = "军事",
                Tips = "历史军事",
                Image = "☭",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 226, 95, 35))
            };
            list.Add(navInfo5);
            var navInfo6 = new NavInfoDx
            {
                Id = 5,
                Title = "游戏",
                Tips = "游戏竞技",
                Image = "⚽",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 36, 188, 206))
            };
            list.Add(navInfo6);
            var navInfo7 = new NavInfoDx
            {
                Id = 6,
                Title = "科幻",
                Tips = "科幻灵异",
                Image = "⚛",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 181, 212, 171))
            };
            list.Add(navInfo7);
            var navInfo8 = new NavInfoDx
            {
                Id = 7,
                Title = "同人",
                Tips = "漫画同人",
                Image = "⚘",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 2, 156, 50))
            };
            list.Add(navInfo8);
            return list;
        }

        public IList<NavInfoDx> GetRightNavInfos()
        {
            IList<NavInfoDx> list = new List<NavInfoDx>();

    
            var navInfo1 = new NavInfoDx
            {
                Id = 101,
                Title = "全本",
                Tips = "全本阅读",
                Image = "❁",
                BackColor = new SolidColorBrush(Color.FromArgb(100, 17, 174, 194))//取自converter
            };
            list.Add(navInfo1);

            //var navInfo3 = new NavInfoDx
            //{
            //    Id = 1002,
            //    Title = "点击榜",
            //    Tips = "点击排行榜",
            //    Image = "☉",
            //    BackColor = new SolidColorBrush(Color.FromArgb(100, 17, 174, 194))//取自converter
            //};
            //list.Add(navInfo3);

            //var navInfo4 = new NavInfoDx
            //{
            //    Id = 1003,
            //    Title = "推荐榜",
            //    Tips = "推荐排行榜",
            //    Image = "☺",
            //    BackColor = new SolidColorBrush(Color.FromArgb(100, 17, 174, 194))//取自converter
            //};
            //list.Add(navInfo4);

            //var nav2 = new Nav
            //{
            //    Id = 2,
            //    Title = "离线缓存",
            //    Image = "⟱"
            //};
            //list.Add(nav2);
            //var nav3 = new Nav
            //{
            //    Id = 3,
            //    Title = "阅读历史",
            //    Image = "❁"
            //};
            //list.Add(nav3);
            return list;
        }
    }
}
